package com.sxt.controller;

import com.sxt.common.DataGridView;


import com.sxt.domain.Goods;
import com.sxt.service.GoodsService;

import com.sxt.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@Controller
@RequestMapping("goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;


    @RequestMapping("main")
    public String main(){
        return "main";
    }


    @RequestMapping("loadAllGoods")
    @ResponseBody
    public DataGridView loadAllGoods(GoodsVo goodsVo){
        return  this.goodsService.queryAllGoods(goodsVo);
    }

    @RequestMapping("addGoods")
    @ResponseBody
    public Map<String,Object> addGoods(Goods goods){
        Map<String,Object> map=new HashMap<>();
        try {
            this.goodsService.save(goods);
            map.put("code",200);
            map.put("msg","添加成功");
            return map;
        }catch (Exception e){
            e.printStackTrace();
            map.put("code",-1);
            map.put("msg","添加失败");
            return map;
        }
    }

}
